﻿using System;
using System.Collections.Generic;
using UnityEngine;

public class PathUnit
{
    public static string GetScriptAssetBundlePath(string path)
    {
        return LoadMrg.Instance.scriptRoot + "/" + path;
    }

    /// <summary>
    /// 获取AssetBundle 输出目录
    /// </summary>
    /// <returns></returns>
    public static string GetAssetBundleOutPath()
    {
        string outPath=GetPlatformPath()+"/"+GetPlatformName();
        if (!System.IO.Directory.Exists(outPath)) System.IO.Directory.CreateDirectory(outPath);
        return outPath;
    }
    public static string GetPlatformPath()
    {
        switch (Application.platform)
        {
            case RuntimePlatform.Android:
                return Application.persistentDataPath;//Application.dataPath + "!assets/";
                break;
            case RuntimePlatform.IPhonePlayer:
                return "iOS";
                break;
            case RuntimePlatform.WindowsEditor:
            case RuntimePlatform.WindowsPlayer:
                return Application.streamingAssetsPath;
                break;
        }
        return null;
    }
    public static string GetStreamingAssetsPath()
    {
        return Application.streamingAssetsPath + "/" + GetPlatformName(); ;
    }
    public static string GetPlatformName()
    {
        switch (Application.platform)
        {
            case RuntimePlatform.Android:
                return "Android";
                break;
            case RuntimePlatform.IPhonePlayer:
                return "iOS";
                break;
            case RuntimePlatform.WindowsEditor:
            case RuntimePlatform.WindowsPlayer:
                return "Android";
                break;
        }
        return null;
    }

    /// <summary>
    /// 获取www协议路径
    /// </summary>
    /// <returns></returns>
    public static string GetWWWPath()
    {
        switch (Application.platform)
        {
            case RuntimePlatform.Android:
                return GetAssetBundleOutPath();//android 不需要加 jar:file://
                break;
            case RuntimePlatform.IPhonePlayer:
                return GetAssetBundleOutPath();
                break;
            case RuntimePlatform.WindowsEditor:
            case RuntimePlatform.WindowsPlayer:
                return GetAssetBundleOutPath();
                break;
        }
        return null;
    }
}